package tw.edu.tku.im.maze;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

public class RegisterRep extends RepPacket {
   int state;
   PlayerInfo playerInfo;
   
   public RegisterRep(int state) {
      this(state, null);
   }
   
   public RegisterRep(int state, String userID, String name) {
      this(state, new PlayerInfo(userID, name));
   }
   
   public RegisterRep(int state, String userID, String name, int ticket) {
      this(state, new PlayerInfo(userID, name, ticket));
   }
   
   public RegisterRep(int state, PlayerInfo playerInfo) {
      this.state = state;
      this.playerInfo = playerInfo;
   }
   
   public void setState(int state) {
      this.state = state;
   }
   public int getState() {
      return this.state;
   }
   
   public void setPlayerInfo(PlayerInfo playerInfo) {
      this.playerInfo = playerInfo;
   }
   public PlayerInfo getPlayerInfo() {
      return this.playerInfo;
   }
   
   public String toJSONString() throws JSONException {
      JSONObject josnObj = new JSONObject();
      JSONObject result = new JSONObject();
      if(this.playerInfo==null) {
         result.put("playerInfo", this.playerInfo);
      }
      else {
         JSONObject playerInfo = new JSONObject(this.playerInfo.toJSONString());
         result.put("playerInfo", playerInfo);
      }
      result.put("state", this.state);
      josnObj.put("result", result);
      josnObj.put("action", "registerResponse");
      return josnObj.toString();
   }

   @Override
   public String getPacketName() {
      return "registerResponse";
   }

   @Override
   public int describeContents() {
      return 0;
   }

   @Override
   public void writeToParcel(Parcel arg0, int arg1) {
      
   }
}
